<?php
/**
 * Created by PhpStorm.
 * User: XT
 * Date: 2017/5/2
 * Time: 14:51
 */

namespace core;
use core\http\Request;
use core\http\Response;

class Cookie
{

    /**
     * 获取对应key的cookie值
     * @param null $key
     * @return array|mixed|null
     */
    public static function get($key = null)
    {
        $key = !empty($key) ? $key : '';
        return Request::getInstance()->get('cookie.' . $key);
    }

    /**
     * 设置对应key的cookie值
     * @param $key
     * @param string $value
     * @param int $expire
     * @param string $path
     * @param string $domain
     * @param bool $secure
     * @param bool $httpOnly
     * @return mixed
     */
    public static function set($key, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httpOnly = false)
    {
        return Response::getInstance()->cookie($key, $value, $expire, $path, $domain, $secure, $httpOnly);
    }

    /**
     * 清除对应key的cookie
     * @param $key
     * @return mixed
     */
    public static function delete($key)
    {
        return Response::getInstance()->cookie($key, null);
    }
}